package partlow.yelp.parsers;

import org.json.JSONException;
import org.json.JSONObject;

import partlow.yelp.datatypes.YelpDeal;

public class DealParser extends YelpTypeParser<YelpDeal> {

	@Override
    public YelpDeal parse(JSONObject json) throws JSONException {
		YelpDeal obj = new YelpDeal();
		if(json.has("what_you_get"))
            obj.setDescription(json.getString("what_you_get"));
		if(json.has("additional_restrictions"))
            obj.getRestrictions().add(json.getString("additional_restrictions"));
		if(json.has("important_restrictions"))
            obj.getRestrictions().add(json.getString("important_restrictions"));
		if(json.has("time_start"))
            obj.setTimeStart(json.getLong("time_start"));
		if(json.has("time_end"))
            obj.setTimeEnd(json.getLong("time_end"));
		if(json.has("options"))
            obj.setDealOptions(new DealOptionParser().parse(json.getJSONArray("options")));
		
		return obj;
	}
}
